<?php


namespace app\admin\controller;


use think\Controller;
use app\admin\model\Login as LoginModel;

class Login extends Controller
{
    public function index(){
        return $this->fetch();
    }

    public function doLogin($username,$password){

        //1.接收数据
//        echo $username;
//        echo $password;
        //2.数据库获取
        $admin=LoginModel::where('username',$username)->find();
        //3.返回
        if(empty($admin)) {
            $this->error('用户不存在');
        }
        if($admin['password'] == $password){
            session('username',$username);
            $this->success('登录成功','user/index');
        }
        else{
            $this->error('用户或密码不正确');
        }
    }

    //退出登录
    public function logout(){
        session(null);
        $this->success('退出成功','login/index');
}


}